package com.example.login;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button button = findViewById(R.id.button);
        button.setOnClickListener(v -> {
            //获得账号密码
            EditText mEditText1 = findViewById(R.id.username);
            EditText mEditText2 = findViewById(R.id.psw);
            String userName = mEditText1.getText().toString();
            String psw = mEditText2.getText().toString();

            //设置对话框
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

            if(userName.equals("abc")) {
                if(psw.equals("123")) {
                    builder.setMessage("上号成昆").setTitle("女子");
                } else {
                    builder.setMessage("密码错误，上号失败！").setTitle("寄");
                }
            } else {
                builder.setMessage("用户名错误，上号失败！").setTitle("寄");
            }
            builder.setPositiveButton("彳亍", (dialog, which) ->
                    Toast.makeText(MainActivity.this, "彳亍", Toast.LENGTH_LONG).show());
            builder.show();
        });
    }
}